<?php
include_once("../../service/receiptService.php");
include_once("../../util/constant.php");

$recId = $_POST["recId"];
$status = $_POST["status"];
$receipt = mysql_fetch_array(findReceiptBy($recId));

if(updateStatus($recId, $status) > 0){
	if($status == 5 && $receipt["REC_STATUS"] != 5){
		if(!updateActuallyDeliveryingDate($recId, date('d/m/Y'))){
			echo UPDATE_FAILED;		
		}
	}else if(($status != 5 && $receipt["REC_STATUS"] == 5) || ($status != 5 && $receipt["REC_STATUS"] != 5)){
    	if(!updateActuallyDeliveryingDate($recId, '') && $receipt["REC_ACTUALLYDELIVERYINGDATE"] != ""){
			echo UPDATE_FAILED;		
		}
    }
	echo UPDATE_SUCCESSFULLY;
}
else
	echo UPDATE_FAILED;
?>